package cn.zc.curriculum.service.controller.admin;

import cn.tools.core.VO.PageVO;
import cn.tools.core.base.R;
import cn.zc.curriculum.entity.Dto.CurriculumVideoDto;
import cn.zc.curriculum.entity.VO.CurriculumVideoVO;
import cn.zc.curriculum.service.service.CurriculumVideoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Api(tags = "后台上传视频接口")
@RestController
@RequestMapping("/curriculum")
public class AdminCurriculumVideoController {

    @Resource
    private CurriculumVideoService curriculumVideoService;

    /**
     * 上传视频至本机，oss，保利威视
     * @param video
     * @return
     */
    @ApiOperation(value = "上传视频,前端先异步调用上传视频，再上传其他信息")
    @PostMapping("/admin/upload/CurriculumVideo")
    private R<Object> uploadCurriculumVideo(MultipartFile video){
        CurriculumVideoVO curriculumVideoVO = curriculumVideoService.uploadCurriculumVideo(video);
        return R.success(curriculumVideoVO);
    }


    /**
     * 删除视频以及本地与云上的文件
     * @param id
     * @return
     */
    @ApiOperation(value = "删除本地以及云上视频文件")
    @DeleteMapping("/admin/delete/CurriculumVideo")
    private R deleteCurriculumVideo(String id){
        curriculumVideoService.deleteCurriculumVideo(id);
        return R.success();
    }



    /**
     * 创建一条视频
     * @return
     */
    @ApiOperation(value = "创建视频")
    @PostMapping("/admin/create/CurriculumVideo")
    private R<Object> createCurriculumVideo(@RequestBody CurriculumVideoDto curriculumVideoDto){
        CurriculumVideoDto videoDto = curriculumVideoService.createCurriculumVideo(curriculumVideoDto);
        return R.success(videoDto);
    }


    /**
     * 修改视频信息
     * @param curriculumVideoDto
     * @return
     */
    @ApiOperation(value = "修改视频")
    @PostMapping("/admin/update/CurriculumVideo")
    private R updateCurriculumVideo(@RequestBody CurriculumVideoDto curriculumVideoDto){
        curriculumVideoService.updateCurriculumVideo(curriculumVideoDto);
        return R.success();
    }


    /**
     * 根据id，目录id，视频后缀，作者id查询视频信息，不传查出所有
     * @param pageVO
     * @param curriculumVideoDto
     * @return
     */
    @ApiOperation(value = "根据id，目录id，视频后缀，作者id查询视频信息，就这几项做了判定，穿其他的不生效")
    @PostMapping("/admin/find/CurriculumVideo")
    private R<Object> findCurriculumVideo(PageVO pageVO,CurriculumVideoDto curriculumVideoDto){
        List<CurriculumVideoDto> videoDto = curriculumVideoService.findCurriculumVideo(pageVO,curriculumVideoDto);
        return R.success(videoDto);
    }

    /**
     * 通过id获取本地视频数据流，以tcp形式进行连接
     * @param request
     * @param response
     * @param videoId
     */
    @ApiOperation(value = "通过id获取本地视频文件视频流，不推荐使用这种方式，不过鉴于老大要测试，可以先给他用着")
    @GetMapping("/admin/find/VideoStream")
    private void findVideoStream(HttpServletRequest request, HttpServletResponse response,String videoId){
        curriculumVideoService.findVideoStream(request,response,videoId);
    }
}
